%{
#include <string.h>
char bfr[20];
%}
%x zig
%%
\<[^>]*\> { ECHO; }
(\[[^\]\[]*(\[[^\]\[]*\][^\]\[]*)*\])+ { ECHO; }

0?1st printf("first");
0?2nd printf("second");
0?3rd printf("third");
0?5th printf("fifth");
0?9th printf("ninth");
12th printf("twelvth");
20th printf("twentieth");
30th printf("thirtieth");
40th printf("fourtieth");
50th printf("fiftieth");
60th printf("sixtieth");
70th printf("seventieth");
80th printf("eightieth");
90th printf("ninetieth");
0/[^0-9] printf("zero");
0 ;
<zig>1/[^0-9] {printf("%s-one",&bfr);BEGIN INITIAL;}
<zig>1st {printf("%s-first",&bfr);BEGIN INITIAL;}
<zig>1000/[^0-9] {printf("%s-one thousand ",&bfr);BEGIN INITIAL;}
<zig>1/[0-9][0-9][0-9][^0-9] {printf("%s-one thousand ",&bfr);BEGIN INITIAL;}
<zig>2/[^0-9] {printf("%s-two",&bfr);BEGIN INITIAL;}
<zig>2nd {printf("%s-second",&bfr);BEGIN INITIAL;}
<zig>2000/[^0-9] {printf("%s-two thousand ",&bfr);BEGIN INITIAL;}
<zig>2/[0-9][0-9][0-9][^0-9] {printf("%s-two thousand ",&bfr);BEGIN INITIAL;}
<zig>3/[^0-9] {printf("%s-three",&bfr);BEGIN INITIAL;}
<zig>3rd {printf("%s-third",&bfr);BEGIN INITIAL;}
<zig>3000/[^0-9] {printf("%s-three thousand ",&bfr);BEGIN INITIAL;}
<zig>3/[0-9][0-9][0-9][^0-9] {printf("%s-three thousand ",&bfr);BEGIN INITIAL;}
<zig>4/[^0-9] {printf("%s-four",&bfr);BEGIN INITIAL;}
<zig>4000/[^0-9] {printf("%s-four thousand ",&bfr);BEGIN INITIAL;}
<zig>4/[0-9][0-9][0-9][^0-9] {printf("%s-four thousand ",&bfr);BEGIN INITIAL;}
<zig>5/[^0-9] {printf("%s-five",&bfr);BEGIN INITIAL;}
<zig>5th {printf("%s-fifth",&bfr);BEGIN INITIAL;}
<zig>5000/[^0-9] {printf("%s-five thousand ",&bfr);BEGIN INITIAL;}
<zig>5/[0-9][0-9][0-9][^0-9] {printf("%s-five thousand ",&bfr);BEGIN INITIAL;}
<zig>6/[^0-9] {printf("%s-six",&bfr);BEGIN INITIAL;}
<zig>6000/[^0-9] {printf("%s-six thousand ",&bfr);BEGIN INITIAL;}
<zig>6/[0-9][0-9][0-9][^0-9] {printf("%s-six thousand ",&bfr);BEGIN INITIAL;}
<zig>7/[^0-9] {printf("%s-seven",&bfr);BEGIN INITIAL;}
<zig>7000/[^0-9] {printf("%s-seven thousand ",&bfr);BEGIN INITIAL;}
<zig>7/[0-9][0-9][0-9][^0-9] {printf("%s-seven thousand ",&bfr);BEGIN INITIAL;}
<zig>8/[^0-9] {printf("%s-eight",&bfr);BEGIN INITIAL;}
<zig>8000/[^0-9] {printf("%s-eight thousand ",&bfr);BEGIN INITIAL;}
<zig>8/[0-9][0-9][0-9][^0-9] {printf("%s-eight thousand ",&bfr);BEGIN INITIAL;}
<zig>9/[^0-9] {printf("%s-nine",&bfr);BEGIN INITIAL;}
<zig>9th {printf("%s-ninth",&bfr);BEGIN INITIAL;}
<zig>9000/[^0-9] {printf("%s-nine thousand ",&bfr);BEGIN INITIAL;}
<zig>9/[0-9][0-9][0-9][^0-9] {printf("%s-nine thousand ",&bfr);BEGIN INITIAL;}
^1700/[^0-9] printf("seventeen hundred ");
[ ]1700/[^0-9] printf(" seventeen hundred ");
^17/[0-9][0-9][^0-9] printf("seventeen hundred ");
[ ]17/[0-9][0-9][^0-9] printf(" seventeen hundred ");
^1800/[^0-9] printf("eighteen hundred ");
[ ]1800/[^0-9] printf(" eighteen hundred ");
^18/[0-9][0-9][^0-9] printf("eighteen hundred ");
[ ]18/[0-9][0-9][^0-9] printf(" eighteen hundred ");
^1900/[^0-9] printf("nineteen hundred ");
[ ]1900/[^0-9] printf(" nineteen hundred ");
^19/[0-9][0-9][^0-9] printf("nineteen hundred ");
[ ]19/[0-9][0-9][^0-9] printf(" nineteen hundred ");
1000/[^0-9] printf("one thousand ");
2000/[^0-9] printf("two thousand ");
3000/[^0-9] printf("three thousand ");
4000/[^0-9] printf("four thousand ");
5000/[^0-9] printf("five thousand ");
6000/[^0-9] printf("six thousand ");
7000/[^0-9] printf("seven thousand ");
8000/[^0-9] printf("eight thousand ");
9000/[^0-9] printf("nine thousand ");
1/[^0-9] printf("one");
1/[0-9][0-9][0-9][^0-9] printf("one thousand ");
2/[^0-9] printf("two");
2/[0-9][0-9][0-9][^0-9] printf("two thousand ");
3/[^0-9] printf("three");
3/[0-9][0-9][0-9][^0-9] printf("three thousand ");
4/[^0-9] printf("four");
4/[0-9][0-9][0-9][^0-9] printf("four thousand ");
5/[^0-9] printf("five");
5/[0-9][0-9][0-9][^0-9] printf("five thousand ");
6/[^0-9] printf("six");
6/[0-9][0-9][0-9][^0-9] printf("six thousand ");
7/[^0-9] printf("seven");
7/[0-9][0-9][0-9][^0-9] printf("seven thousand ");
8/[^0-9] printf("eight");
8/[0-9][0-9][0-9][^0-9] printf("eight thousand ");
9/[^0-9] printf("nine");
9/[0-9][0-9][0-9][^0-9] printf("nine thousand ");
10/[^0-9] printf("ten");
10/[0-9][0-9][0-9][^0-9] printf("ten thousand ");
11/[^0-9] printf("eleven");
11/[0-9][0-9][0-9][^0-9] printf("eleven thousand ");
12/[^0-9] printf("twelve");
12/[0-9][0-9][0-9][^0-9] printf("twelve thousand ");
13/[^0-9] printf("thirteen");
13/[0-9][0-9][0-9][^0-9] printf("thirteen thousand ");
14/[^0-9] printf("fourteen");
14/[0-9][0-9][0-9][^0-9] printf("fourteen thousand ");
15/[^0-9] printf("fifteen");
15/[0-9][0-9][0-9][^0-9] printf("fifteen thousand ");
16/[^0-9] printf("sixteen");
16/[0-9][0-9][0-9][^0-9] printf("sixteen thousand ");
17/[^0-9] printf("seventeen");
17/[0-9][0-9][0-9][^0-9] printf("seventeen thousand ");
18/[^0-9] printf("eighteen");
18/[0-9][0-9][0-9][^0-9] printf("eighteen thousand ");
19/[^0-9] printf("nineteen");
19/[0-9][0-9][0-9][^0-9] printf("nineteen thousand ");
20/[^0-9] printf("twenty");
20/[0-9][0-9][0-9][^0-9] printf("twenty thousand ");
30/[^0-9] printf("thirty");
30/[0-9][0-9][0-9][^0-9] printf("thirty thousand ");
40/[^0-9] printf("fourty");
40/[0-9][0-9][0-9][^0-9] printf("fourty thousand ");
50/[^0-9] printf("fifty");
50/[0-9][0-9][0-9][^0-9] printf("fifty thousand ");
60/[^0-9] printf("sixty");
60/[0-9][0-9][0-9][^0-9] printf("sixty thousand ");
70/[^0-9] printf("seventy");
70/[0-9][0-9][0-9][^0-9] printf("seventy thousand ");
80/[^0-9] printf("eigthy");
80/[0-9][0-9][0-9][^0-9] printf("eigthy thousand ");
90/[^0-9] printf("ninety");
90/[0-9][0-9][0-9][^0-9] printf("ninety thousand ");
2/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "twenty");BEGIN zig;}
3/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "thirty");BEGIN zig;}
4/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "fourty");BEGIN zig;}
5/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "fifty");BEGIN zig;}
6/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "sixty");BEGIN zig;}
7/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "seventy");BEGIN zig;}
8/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "eigthy");BEGIN zig;}
9/[0-9][0-9][0-9][0-9][^0-9] {strcpy(bfr, "ninety");BEGIN zig;}
2/[0-9][^0-9] {strcpy(bfr, "twenty");BEGIN zig;}
3/[0-9][^0-9] {strcpy(bfr, "thirty");BEGIN zig;}
4/[0-9][^0-9] {strcpy(bfr, "fourty");BEGIN zig;}
5/[0-9][^0-9] {strcpy(bfr, "fifty");BEGIN zig;}
6/[0-9][^0-9] {strcpy(bfr, "sixty");BEGIN zig;}
7/[0-9][^0-9] {strcpy(bfr, "seventy");BEGIN zig;}
8/[0-9][^0-9] {strcpy(bfr, "eigthy");BEGIN zig;}
9/[0-9][^0-9] {strcpy(bfr, "ninety");BEGIN zig;}
100000/[^0-9] {printf("one hundred  thousand ");}
100/[^0-9] {printf("one hundred ");}
100/[0-9][0-9][0-9][^0-9] {printf("one hundred  thousand ");}
1/[0-9][0-9][^0-9] {printf("one hundred ");}
1/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("one hundred ");}
200/[^0-9] {printf("two hundred ");}
200/[0-9][0-9][0-9][^0-9] {printf("two hundred  thousand ");}
2/[0-9][0-9][^0-9] {printf("two hundred ");}
2/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("two hundred ");}
300/[^0-9] {printf("three hundred ");}
300/[0-9][0-9][0-9][^0-9] {printf("three hundred  thousand ");}
3/[0-9][0-9][^0-9] {printf("three hundred ");}
3/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("three hundred ");}
400/[^0-9] {printf("four hundred ");}
400/[0-9][0-9][0-9][^0-9] {printf("four hundred  thousand ");}
4/[0-9][0-9][^0-9] {printf("four hundred ");}
4/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("four hundred ");}
500/[^0-9] {printf("five hundred ");}
500/[0-9][0-9][0-9][^0-9] {printf("five hundred  thousand ");}
5/[0-9][0-9][^0-9] {printf("five hundred ");}
5/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("five hundred ");}
600/[^0-9] {printf("six hundred ");}
600/[0-9][0-9][0-9][^0-9] {printf("six hundred  thousand ");}
6/[0-9][0-9][^0-9] {printf("six hundred ");}
6/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("six hundred ");}
700/[^0-9] {printf("seven hundred ");}
700/[0-9][0-9][0-9][^0-9] {printf("seven hundred  thousand ");}
7/[0-9][0-9][^0-9] {printf("seven hundred ");}
7/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("seven hundred ");}
800/[^0-9] {printf("eight hundred ");}
800/[0-9][0-9][0-9][^0-9] {printf("eight hundred  thousand ");}
8/[0-9][0-9][^0-9] {printf("eight hundred ");}
8/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("eight hundred ");}
900/[^0-9] {printf("nine hundred ");}
900/[0-9][0-9][0-9][^0-9] {printf("nine hundred  thousand ");}
9/[0-9][0-9][^0-9] {printf("nine hundred ");}
9/[0-9][0-9][0-9][0-9][0-9][^0-9] {printf("nine hundred ");}
%%
main(argc, argv)
int argc;
char **argv;
{
  int i;

  ++argv; --argc; /* skip over program name */

  if(argc>0){
    for(i=0; i<argc; i++){
      yyin = fopen(argv[i],"r");
      if (yyin==NULL) 
        fprintf(stderr,"could not open %s --- skipped.\n",argv[i]);
      else {
        yylex();
      }
    }
  } else {
    yyin=stdin;
    yylex();
  }
}

